package com.d3works.studio.db.repo;

import com.d3works.studio.db.AppBuilder;
import com.d3works.studio.db.WsConnector;
import com.d3works.studio.db.WsRequest;
import java.util.List;
import org.apache.commons.collections.CollectionUtils;

public class WsConnectorRepo extends WsConnectorRepository {

  @Override
  public WsConnector save(WsConnector connector) {
    connector = super.save(connector);

    List<WsRequest> requests = connector.getWsRequestList();
    if (CollectionUtils.isEmpty(requests)) {
      return connector;
    }

    final AppBuilder appBuilder = connector.getAppBuilder();
    requests.forEach(
        req -> {
          req.setAppBuilder(appBuilder);
        });

    return connector;
  }
}
